package com.manage.demo.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.apache.logging.log4j.LogManager;
//import org.apache.logging.log4j.Logger;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.manage.demo.service.ExamResultsService;
import com.manage.demo.service.TeacherService;

@Controller

public class analysisController {
    @Autowired
    private ExamResultsService ExamResultsService;   
    @Autowired
    private TeacherService TeacherService;

    // 获取画面所需的列表信息
    @RequestMapping("/get_result")
    public String get_result(Model model){
        System.out.println("获得列表！！！");
        // 考试年份
        List<String> yearList = new ArrayList<String>();
        for(String row : ExamResultsService.getYear()) {
            if(!yearList.contains(row)) {
                yearList.add(row);
            }
        };
        Collections.sort(yearList);
        model.addAttribute("year",yearList);

        // 科目
        model.addAttribute("course", TeacherService.getcourse());

        return "html/result_analysis.html";
    }
    
 // 获取画面所需的成绩信息
    @RequestMapping(value="/result_analysis", method=RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getAnalysis(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "year", required = false) String year,
            @RequestParam(value = "examtype", required = false) String examtype
            ){
        Map<String, Object> results = new HashMap<String, Object>();
        results.put("data", ExamResultsService.getResults(year, examtype));
        return results;
    }
}
